<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // navigator   -> window.navigator (设备相关的信息)
    // userAgent  用户代理信息，通过该属性可以获取浏览器及操作系统信息

    // PC: Windows Mac
    // 移动端: Android  iPhone   iPad

    // console.log(navigator);
    // console.log(navigator.userAgent);


    // 判断一个设备是否移动端?

    // var appList = ['Android', 'iPhone', 'iPad','BB10'];
    // var userAgent = navigator.userAgent;
    // console.log(userAgent);

    // var flag = false; // 假设不是移动端
    // for (var i = 0; i < appList.length; i++) {
    //     var app = appList[i];  // 'Android', 'iPhone', 'iPad'
    //     if (userAgent.indexOf(app) != -1) {
    //         flag = true;
    //         break;
    //     }
    // }
    // if (flag) {
    //     document.write("移动端:" + app);
    // } else {
    //     document.write("PC端");
    // }


    function isApp() {
        var appList = ['Android', 'iPhone', 'iPad'];
        var userAgent = navigator.userAgent;
        console.log(userAgent);

        var flag = false; // 假设不是移动端
        for (var i = 0; i < appList.length; i++) {
            var app = appList[i];  // 'Android', 'iPhone', 'iPad'
            if (userAgent.indexOf(app) != -1) {
                flag = true;
                break;
            }
        }
        return {
            status: flag,
            type: flag ? app : "PC",
        }
    }

    document.onclick = function () {
        var result = isApp();
        if (result.status) {
            location.href = "https://m.jd.com";
        } else {
            location.href = "https://jd.com";
        }
    }







</script>

</html>